import {FC} from "react";
import {DatePicker} from "antd";

const {RangePicker} = DatePicker;

interface RPickProps {
    width?: number;
    isDisabledDate?: boolean;
    setStartTime?: (e?: any) => void;
    setEndTime?: (e?: any) => void;
    [key: string]: any;
}
const RPick: FC<RPickProps> = ({width = 240, isDisabledDate = true, setStartTime, setEndTime}) => {
    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
    //@ts-ignore
    const handleChange = (data, dateString) => {
        setStartTime(dateString[0]);
        setEndTime(dateString[1]);
    };

    const handleDisabledDate = current => current && current > new Date();
    const config = {
        ...(isDisabledDate ? {disabledDate: handleDisabledDate} : {}),
        onChange: handleChange,
    };

    return <RangePicker style={{width}} {...config} />;
};

export default RPick;
